package pool.bean;

import java.sql.ResultSet;
import java.util.Enumeration;
import java.util.Hashtable;


import dbmanager.DBManager;

public class IdBean 
{
	DBManager database;
	String id;
	String tableName;
	public IdBean(DBManager database)
	{
		this.database = database;
	}
	
	public String getId()
	{
		return id;
	}
	
	public void setTable(String tableName)
	{
		this.tableName = tableName;
	}

	public void setId(String id)
	{
		this.id = id;
	}
	
	public void update()
	{
		database.getUpdate("update max_id_table set id ='"+(Integer.parseInt(id)+1)+"' where table_name ='"+tableName+"'");	
	
	}
	public void execute()
	{
		try
		{	
			ResultSet rs = database.getSelect("select id from max_id_table where table_name = '"+tableName+"'");
			rs.next();
			id = rs.getString("id");
			rs.close();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
	
	/*public Hashtable<Object, Object> checkField(Hashtable<Object,Object> PHash,String tablename,String process)
	{
		Boolean flage=false;
		try
		{
			ResultSet rs1 = database.getSelect("SELECT fieldname FROM command where msgtype = '"+tablename+"' and process = '"+process+"'");
			Enumeration<Object> enumtransaction = PHash.keys();
			while(enumtransaction.hasMoreElements())
			{
				
				flage=false;
				String col = enumtransaction.nextElement().toString();
				while(rs1.next())
				{
					String colname  = rs1.getString("fieldname").toLowerCase();
					if(col.equals(colname))
					{
						flage=true;
						
					}
					
				}	
				if(flage==false)
				{
					
					PHash.put("ErrorInput", "Key field  "+col+"  is not present in "+tablename);
					return PHash;
					
				}
				rs1.beforeFirst();
				
			}
		}
		catch (Exception e1) 
		{
			e1.printStackTrace();
		}
	
		return PHash;
		
	}*/
	
	
}
